package com.karson.admin.task;

import com.karson.service.dao.UserActionMapper;
import com.karson.service.service.AlbumInfoService;
import com.karson.service.service.RecommendService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;


/**
 * @author ZKS
 */
@Component
@Log4j2
@Configuration
public class RecommendTask {
    @Autowired
    private RecommendService recommendService;

    @Autowired
    private AlbumInfoService albumInfoService;

    @Scheduled(cron = "0 0 * * * ?")
    public void calculateHotValue() {
        long start = System.currentTimeMillis();
        LocalDateTime startTime = LocalDateTime.now();
        log.info("【HotValue定时任务】开始执行：{}", startTime);

        try {
            albumInfoService.recommendAllHotRank();
            long end = System.currentTimeMillis();
            LocalDateTime endTime = LocalDateTime.now();
            log.info("【HotValue定时任务】执行结束：{}，耗时：{} ms", endTime, (end - start));
        } catch (Exception e) {
            log.error("【HotValue定时任务】执行异常：", e);
        }
    }
    /**
     * 热门推荐
     */
    @Scheduled(cron = "0 55 23 * * ?")
    public void getHotDayRecommendTask() {
        // 每日23：55 结算
        try {
            recommendService.dailySettlement();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Scheduled(cron = "0 0 0 1 * ?")
    public void getMonthHotRecommendTask() {
        // 每日23：55 结算
        try {
            recommendService.monthSettlement();
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
